﻿// <copyright file="IConnexityProvider.cs" company="Ecole Normale Supérieure">
// Released under GPLv2
// </copyright>
// <summary>Contains the interface IConnexityProvider, an interface of connexity verification.</summary>

namespace Sqwarea.GameLogic.Connexity
{
    using System.Collections.Generic;
    using System.Drawing;
    using Sqwarea.Persistence;

    /// <summary>
    /// Interface pour la vérification de la connexité des royaumes.
    /// Le constructeur prendra en argument le KingId de la case quand elle a été perdue.
    /// En plus des coordonnées de cette case.
    /// En effet, la connexité est vérifiée postérieurement à l'attaque, 
    /// Donc on ne peut pas regarder directement sur la case.
    /// </summary>
    public interface IConnexityProvider
    {
        /// <summary>
        /// Verify if connexity is broken, and if it is, it repairs it.
        /// Needs not only the square, but also its former owner,
        /// Because, ownership have already changed due to an attack
        /// Called by AttackSolver.
        /// </summary>
        /// <param name="breakpoint">Wrapper upon the coordinates of the case to be examined and the Id of its former King</param>
        /// <returns>True iff it success</returns>
        bool EnforceConnexity(ConnexityBreakpoint breakpoint);

        /// <summary>
        /// Called on a case just stolen, maintain the invariant of PathToKing
        /// (regarding the new player, EnforceConnexity still needs to be called for the square former owner).
        /// Called directly by AttackSolver.
        /// If it cannot manage to create a PathToKing (an anomaly that can be caused by concurrent access), 
        /// it makes the case to go neutral and call EnforceConnexity on it.
        /// </summary>
        /// <param name="position">The position of the square to be updated.</param>
        /// <returns>True iff it success</returns>
        bool ConnexityAnnexSquare(Point position);

        /// <summary>
        /// Repairs connexity in a set of squares for a given king
        /// </summary>
        /// <param name="kingId">The given king.</param>
        /// <param name="cases">The set of squares, indexed by position.toalphastring</param>
        void RepairsConnexity(long kingId, Dictionary<string, Square> cases);
    }
}
